package com.danco.training.zaneuskaya.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Zaneuskaya Aliaksandra
 *
 */
@Entity
@Table(name = "forum")
public class Forum implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5008888580030462972L;

	@Id
	@GeneratedValue
	@Column(name = "forum_id")
	private Integer forumId;

	@Column(name = "forum_title")
	private String forumTitle;

	@Column(name = "forum_description")
	private String forumDescription;

	@Column(name = "enable_reading")
	private boolean enableReading;

	@Column(name = "enable_writing")
	private boolean enableWriting;

	@Column(name = "date_creation")
	@Temporal(value = TemporalType.DATE)
	private Date forumCreationDate;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "administrator_fk", referencedColumnName = "user_id")
	private User administrator;

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "user_forum", joinColumns = { @JoinColumn(name = "forum_fk") }, inverseJoinColumns = { @JoinColumn(name = "user_fk") })
	private Set<User> members = new HashSet<User>();

	@OneToMany(fetch = FetchType.LAZY)
	@JoinColumn(name = "forum_fk")
	private Set<Note> forumNotes = new HashSet<Note>();

	public Integer getForumId() {
		return forumId;
	}

	public void setForumId(Integer forumId) {
		this.forumId = forumId;
	}

	public String getForumTitle() {
		return forumTitle;
	}

	public void setForumTitle(String forumTitle) {
		this.forumTitle = forumTitle;
	}

	public String getForumDescription() {
		return forumDescription;
	}

	public void setForumDescription(String forumDescription) {
		this.forumDescription = forumDescription;
	}

	public boolean isEnableReading() {
		return enableReading;
	}

	public void setEnableReading(boolean enableReading) {
		this.enableReading = enableReading;
	}

	public boolean isEnableWriting() {
		return enableWriting;
	}

	public void setEnableWriting(boolean enableWriting) {
		this.enableWriting = enableWriting;
	}

	public Date getForumCreationDate() {
		return forumCreationDate;
	}

	public void setForumCreationDate(Date forumCreationDate) {
		this.forumCreationDate = forumCreationDate;
	}

	public User getAdministrator() {
		return administrator;
	}

	public void setAdministrator(User administrator) {
		this.administrator = administrator;
	}

	public Set<User> getMembers() {
		return members;
	}

	public void setMembers(Set<User> members) {
		this.members = members;
	}

	public Set<Note> getForumNotes() {
		return forumNotes;
	}

	public void setForumNotes(Set<Note> forumNotes) {
		this.forumNotes = forumNotes;
	}

	@Override
	public int hashCode() {
		return getForumId();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Forum) {
			Forum other = (Forum) obj;
			return other.getForumId() == forumId;
		}
		return false;
	}

}
